const utils = require('../utils');

module.exports = (sequelize, Sequelize) => {
    return sequelize.define("pure_users", {
        id: {
            type: Sequelize.INTEGER,
            notNull: true,
            primaryKey: true,
            autoIncrement: true
        },
        user_name: {
            type: Sequelize.STRING(50),
            notNull: true,
            notEmpty: true,
            comment: '账号',
        },
        nick_name: {
            type: Sequelize.STRING,
            comment: '昵称',
        },
        avatar: {
            type: Sequelize.STRING,
            defaultValue: 'https://avatars.githubusercontent.com/u/44761321',
            comment: '头像',
        },
        phone: {
            type: Sequelize.STRING(20),
            comment: '手机号',
        },
        email: {
            type: Sequelize.STRING(50),
            comment: '邮箱',
        },
        sex: {
            type: Sequelize.INTEGER,
            comment: '性别 0:女 1:男',
        },
        status: {
            type: Sequelize.BOOLEAN,
            defaultValue: 1,
            comment: '状态 0:禁用 1:启用',
        },
        password: {
            type: Sequelize.STRING,
            notEmpty: true,
            comment: '密码',
            set(value) {
                this.setDataValue('password', utils.crypto.aes.en(value));
            },
            get() {
                let pwd = this.getDataValue('password');
                if (!pwd) return '';
                return utils.crypto.aes.de(pwd);
            }
        },
        remark: {
            type: Sequelize.STRING(250),
            comment: '备注',
        },
        description: {
            type: Sequelize.STRING(250),
            comment: '简介',
        },
    },{
        comment:'用户表', 
    });
};
